package LCR_code;

import java.util.Arrays;

/**
 * 适龄的朋友
 *
 * @author blh
 * @date 2024年11月17日 10:02
 */
public class Lee_825_1117 {
    public int numFriendRequests(int[] ages) {
        int res = 0;
        // 直接使用桶排序
        int[] people = new int[121];
        Arrays.fill(people, 0);
        // 记录所有年龄的人的数量
        for (int age : ages) {
            people[age]++;
        }

        for (int i = people.length - 1; i > 0; i--) {
            if (people[i] == 0) {
                continue;
            }
            // 记录同龄人
            if ((0.5 * i + 7) < i) {
                res = res + (people[i] - 1) * people[i];
            }

            for (int j = i - 1; j > 0; j--) {
                if (people[j] == 0) {
                    continue;
                }
                if ((0.5 * i + 7) >= j) {
                    continue;
                }
                res = res + people[i] * people[j];
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Lee_825_1117 method = new Lee_825_1117();
        System.out.print(method.numFriendRequests(new int[]{73, 106, 39, 6, 26, 15, 30, 100, 71, 35, 46, 112, 6, 60, 110}));
    }
}
